<?php

namespace App\Console\Commands;

use Illuminate\Console\Command;
use Hanson\Vbot\Foundation\Vbot as Bot;
use Vbot\Blacklist\Blacklist;
use Vbot\GuessNumber\GuessNumber;
use Vbot\HotGirl\HotGirl;

use App\Http\Controllers\Vbot\MessageHandlerController as MessageHandler;
use App\Http\Controllers\Vbot\ObserverController as Observer;
use Hanson\Vbot\Message\Text;

class Vbot extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'vbot:run';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'vbot running';

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Execute the console command.
     *
     * @return mixed
     */
    public function handle()
    {
        $config = config('vbot');
        $vbot = new Bot($config);

        $vbot->messageHandler->setHandler([MessageHandler::class, 'messageHandler']);
        $vbot->messageExtension->load([
            // some extensions
            Blacklist::class,
            GuessNumber::class,
//            HotGirl::class,
        ]);
        $vbot->observer->setQrCodeObserver([Observer::class, 'setQrCodeObserver']);
        $vbot->observer->setLoginSuccessObserver([Observer::class, 'setLoginSuccessObserver']);
        $vbot->observer->setReLoginSuccessObserver([Observer::class, 'setReLoginSuccessObserver']);
        $vbot->observer->setExitObserver([Observer::class, 'setExitObserver']);
        $vbot->observer->setFetchContactObserver([Observer::class, 'setFetchContactObserver']);
        $vbot->observer->setBeforeMessageObserver([Observer::class, 'setBeforeMessageObserver']);
        $vbot->observer->setNeedActivateObserver([Observer::class, 'setNeedActivateObserver']);
        $vbot->server->serve();


//        $vbot->messageHandler->setHandler(function ($message) {
//            Text::send($message['from']['UserName'], 'Hi, I\'m Vbot!');
//        });
//        $vbot->server->serve();
    }
}
